package concurrent.juc.reentrantlock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author: 黄嘉振
 * @create: 2023/6/15 16:16
 * @description:
 **/
public class FairLockDemo {
    public static void main(String[] args) {
        FairLockTask task = new FairLockTask();
        new Thread(task, "T1").start();
        new Thread(task, "T2").start();
        new Thread(task, "T3").start();
        new Thread(task, "T4").start();
        new Thread(task, "T5").start();
        new Thread(task, "T6").start();
    }
}
class FairLockTask implements Runnable {
    // 非公平锁
//    ReentrantLock lock = new ReentrantLock(false);
    ReentrantLock lock = new ReentrantLock(true);

    @Override
    public void run() {
        try {
            lock.lock();
            System.out.println(Thread.currentThread().getName() + " lock !");
        } finally {
            lock.unlock();
        }
    }
}
